﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Text;

namespace UserNotificationAspMvc.Models
{
    public class ImageList
    {
        public List<Image> Images { get; set; }
        public const ushort PageSize = 30; //30 pics , 5 rows
        
        public ImageList(HttpContextBase context)
        {
            Images = new List<Image>();
            DirectoryInfo imagesDirectory = new DirectoryInfo(context.Server.MapPath("~/images"));
            foreach (FileInfo file in imagesDirectory.GetFiles())
            {
                Image img = new Image(Path.GetFileName(file.FullName));
                Images.Add(img);
            }
        }

        public List<Image> GetNextPage(ushort skip)
        {
            List<Image> nextBatch = Images.Skip(skip * PageSize).Take(PageSize).ToList();
            return nextBatch;
        }

        public string GetNextPageStrings(ushort skip)
        {
            List<Image> batch = GetNextPage(skip);
            StringBuilder sb = new StringBuilder();
            foreach (var img in batch)
            {
                sb.Append(img.ToString());
            }
            return sb.ToString();
        }


    }
}